#include <stdio.h>
#include <string.h>

#define MAXTITL 41
#define MAXAUTH 31

char * s_gets(char * st, int n);

struct book
{
    char title[MAXTITL];
    char author[MAXAUTH];
    double value;
};

int main(void)
{
    struct book library;

    printf("Please enter the book title:\n");
    s_gets(library.title, MAXTITL);

    printf("Please enter the author:\n");
    s_gets(library.author, MAXAUTH);

    printf("Please enter the value:\n");
    scanf("%lf", &library.value);

    printf("%s by %s: $%.2f\n", library.title, library.author, library.value);
    printf("%s: \"%s\" ($%.2f)\n", library.author, library.title, library.value);

    return 0;
}


char * s_gets(char * st, int n)
{
    char * ret_val;
    char * find;

    ret_val = fgets(st, n, stdin);

    if (ret_val)
    {
        if (find = strrchr(st, '\n'))
            *find = '\0';
        
        else
        {   
            while (getchar() != '\n')
                continue;
        }
    }

    return ret_val;
}